package assign1;

/**
 *
 * @author kevin louis
 */
/** main user interface*/
public class MainUI {

    private ProjModel pm;
    private GridView gv;
/**menu constructor*/
    public MainUI() {
        pm = new ProjModel();
        gv = new GridView(this.pm);
    }
/**display the menu*/
    public void displayMenu() {
        while (true) {
            gv.initiGrid('#');/**initiate grid with '#'*/
            gv.buildRoad();/**build the road lane*/
            System.out.print(" === MENU ===\n"
                    + " 1. Set Number of horizontal lanes (H-street) [min 1, max 3]\n"
                    + " 2. Set Number of vertical lanes  (V-street) [min 1, max 4]\n"
                    + " 3. Set Probability of a car entering H-street [min 0, max 1]\n"
                    + " 4. Set Probability of a car entering V-street [min 0, max 1]\n"
                    + " 5. Run one simulation cycle\n"
                    + " 6. Set and run number of simulation cycles [min 1, max 10]\n"
                    + " ");
            String userChoice = GetInput.getUserInput("Enter your choice>");
            int userChoiceInt = Integer.parseInt(userChoice);
            switch (userChoiceInt) {
                case 1:
                    System.out.println("Menu 1");
                    setHorLanesNum();
                    break;
                case 2:
                    System.out.println("Menu 2");
                    setVerLanesNum();
                    break;
                case 3:
                    System.out.println("Menu 3");
                    setProbH();
                    break;
                case 4:
                    System.out.println("Menu 4");
                    setProbV();
                    break;
                case 5:
                    System.out.println("Menu 5");
                    sim();
                    break;
                case 6:
                    System.out.println("Menu 6");
                    simCycle();
                    break;
                default:
                    System.out.println("Error in entering menu choice");
                    break;
            }
        }
    }
/**if menu 1 chosen(set the horizontal lane*/
    public void setHorLanesNum() {
        String userOption = GetInput.getUserInput("Enter number of horizontal lanes: ");
        int userIntOption = Integer.parseInt(userOption);
        //int lower=1;
        //int upper=3;
        if (userIntOption < 1 || userIntOption > 3) {/**if user enter wrong number*/
            System.out.println("Error in entering horizontal lines\nPlease enter number between 1-3");
            displayMenu();
        } else {
            /**if the user enter the correct number*/
            pm.sethorLanes(userIntOption);
            /**set the horizontal lanes*/
        }
    }
/**if menu 2 chosen(set the vertical lanes*/
    public void setVerLanesNum() {
        String userOption = GetInput.getUserInput("Enter number of vertical lanes: ");
        int userIntOption = Integer.parseInt(userOption);
        int lower = 1;
        int upper = 4;
        if (userIntOption < lower || userIntOption > upper) {
            System.out.println("Error in entering  vertical lanes\nPlease enter number between 1-4");
            displayMenu();
        } else {
            /**if the user enter the correct number*/
            pm.setverLanes(userIntOption);
            /**set the horizontal lanes*/
        }
    }
/**if menu 3 chosen(set probability for H lane cars)*/
    public void setProbH() {
        String userOption = GetInput.getUserInput("Enter probability car on H-Lanes[1-0]: ");
        double userDouOption = Double.parseDouble(userOption);

        if (userDouOption > 1 || userDouOption < 0) {
            System.out.println("Error in entering probability\nPlease enter number from 0 - 1");
            displayMenu();
        } else {
            pm.setHorProb(userDouOption);
            System.out.println("Probability entered is " + pm.getHorProb());
        }

    }
/**if menu 4 chosen(set probability for V lane cars)*/
    public void setProbV() {
        String userOption = GetInput.getUserInput("Enter probability car on V-Lanes[1-0]: ");
        double userDouOption = Double.parseDouble(userOption);

        if (userDouOption > 1 || userDouOption < 0) {
            System.out.println("Error in entering probability\nPlease enter number from 0 - 1");
            displayMenu();
        } else {
            pm.setVerProb(userDouOption);
            System.out.println("Probability entered is " + pm.getVerProb());
        }

    }
/** run the simulation one time*/
    public void sim() {
        gv.runSim(pm, 1 );
    }
/**set the simulation time and run it*/
    public void simCycle() {
        String userOption = GetInput.getUserInput("Enter simulation cycle time[0-10]: ");
        int userIntOption = Integer.parseInt(userOption);

        if (userIntOption > 10 || userIntOption < 0) {
            System.out.println("Error in entering simulation cycle time\nPlease enter number from 0 - 10 ");
            displayMenu();
        } else {
            pm.setCycleNum(userIntOption);
            gv.runSim(pm, userIntOption);

        }
    }
}
// public int showHorLanes() {
//  return pm.gethorLanes();
//}
//public int showVerLanes() {
//  return pm.getverLanes();
//}